//
//  MainViewController.swift
//  WeiBoSwift
//
//  Created by zc on 16/6/17.
//  Copyright © 2016年 zc. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    //使用OC特性
   @objc private func composedDidClick(){
        print(#function)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //由于tabBar 是只读 不能直接操作，如果要修改 可以使用KVC
        let mainTabBar = MainTabBar()
        //KVC 赋值
        setValue(mainTabBar, forKey: "tabBar")
        
        //添加子视图控制器
        addChildViewControllers()
        //设置点击事件
        mainTabBar.composeBtn.addTarget(self, action: #selector(composedDidClick), forControlEvents: UIControlEvents.TouchUpInside)
        //classForCoder 打印函数的类名
       // print(tabBar.classForCoder)
        
        // Do any additional setup after loading the view.
        
    }
    //私有
    private func addChildViewControllers() {
       addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
        
    }
    //重载
    private func addChildViewController(vc: UIViewController,title: String,imageName: String){
        //简单方法
        
        //修改图片渲染颜色
        //        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)

        
        //实例化导航视图控制器
        let nav = UINavigationController(rootViewController: vc)
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
               //添加子视图控制器
        addChildViewController(nav)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
